import time
#读取操作r
f=open("C:/Users\徐赛坤\Desktop\Harmony.txt","r",encoding="UTF-8")
print(type(f))

#print(f"{f.read()}")
list1=f.readlines()#获取全部行 封装到列表中
#print(f"{list1}")
for x in list1:
    print(f"{x}")
list2=f.readline()
list3=f.readline()
list4=f.readline()
print(f"{list2}")
print(f"{list3}")
print(f"{list4}")


f.close()

#执行完之后自动的关闭

with open("C:/Users\徐赛坤\Desktop\Harmony.txt","r",encoding="UTF-8") as f:
    for x in f:#一读读一行
        x.strip()
        print(f"{f}")


#1.打开文件,aaew会报字符编码错误
f=open("C:/徐赛坤\Desktop\aaew.txt","w",encoding="UTF-8")

#2.文件写入,存储到缓冲区，不写入文件
f.write("Hello World!!")
time.sleep(5)
#3.内容刷新,一次性写入到文件中
f.flush()
 #   f.close() close内置了flush的功能
#1.打开文件
f=open("C:/Users\徐赛坤\Desktop\ew.txt","w",encoding="UTF-8")

#2.文件写入,存储到缓冲区，不写入文件
f.write("Hello World!!\n")
#writelines参数为一个列表
list1=["徐赛坤\n","王怡戈\n","马远\n"]
f.writelines(list1)
#3.内容刷新,一次性写入到文件中
f.flush()
 #   f.close() close内置了flush的功能
def sss():
    print("dasd")
#a是追加内容,w会把原有的文件清空还是write



